package velox.jcr.mapper;


/**
 * The SecondLevelCache contains two cache regions, denoted by CacheType
 * The different regions have different flush policies. The entity region
 * is used by entities and is flushed on a per key basis. This means that updating
 * an entity means only flushing that particular object. The AUX region is
 * used for caching data that is not easy flush object by object. For instance
 * query results may change when other entities are updated and it is very difficult
 * to keep track of what queries in the cache to flush. Therefore the AUX region
 * is flushed on any modification of the underlying repository.
 * 
 * The SecondLevelCache is only added to by read-only transaction and only flushed
 * by read-write transaction. This is a reasonable trade off to make transaction 
 * handling easier.
 * 
 * @see CacheType
 *
 */
public interface SecondLevelCache {
	public void put(String key, Object obj, CacheType flushOn);
	public void invalidateAux();
	public void invalidateEntity(String key);
	public void invalidateAll();
	public Object get(String key, CacheType cacheType);
	
	public static class Null implements SecondLevelCache {
		public Object get(String key, CacheType cacheType) {
			return null;
		}

		public void put(String key, Object obj, CacheType flushOn) {
		}

		public void invalidateAux() {
		}

		public void invalidateEntity(String key) {
		}

		public void invalidateAll() {
		}
	}

}
